package com.ivi.car.module.store.view;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.ivi.car.R;
import com.ivi.car.module.city.view.CityActivity;
import com.ivi.car.module.store.presenter.StorePresenter;
import com.ivi.car.base.BaseActivity;
import com.wm.machine.baselibrary.common.widget.layout.TitleBar;
import com.wm.machine.baselibrary.common.widget.recyclerview.itemdecoration.SpaceItemDecoration;
import com.wm.machine.baselibrary.utils.DensityUtils;

import butterknife.BindView;


/**
 * 商城城市界面
 */

public class StoreActivity extends BaseActivity {
    @BindView(R.id.store_title_bar)
    TitleBar mStoreTitleBar;
    @BindView(R.id.store_recyclerView)
    RecyclerView mStoreRecyclerView;
    private StorePresenter mStorePresenter;
    private final int topBottom = 10;
    private String loactionCity = "上海";
    private final  int requestCode = 1;
    private final  int textSize = 18;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_strore;
    }

    @Override
    protected void initView() {
        mStoreTitleBar.setLeftDrawable(R.mipmap.back_icon);
        mStoreTitleBar.setTitle("选择门店");
        mStoreTitleBar.setTitleColor(Color.WHITE);
        mStoreTitleBar.setTitleSize(DensityUtils.dp2px(getApplicationContext(), textSize));
        mStoreTitleBar.setRightText(loactionCity);
        mStoreTitleBar.setRightextColor(Color.parseColor("#32CD99"));
        mStoreTitleBar.setRightTextSize(DensityUtils.dp2px(getApplicationContext(), textSize));
        mStoreTitleBar.setLeftClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        mStoreTitleBar.setRightClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), CityActivity.class);
                intent.putExtra("locationCity", loactionCity);
                startActivityForResult(intent, requestCode);
            }
        });
    }

    @Override
    protected void initData() {
        mStorePresenter = new StorePresenter();
       String addressName = mStorePresenter.getAddressName();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(
                getApplicationContext(), LinearLayoutManager.VERTICAL, false);
        SpaceItemDecoration spaceItemDecoration = new SpaceItemDecoration(0, topBottom);
        mStoreTitleBar.setRightText(addressName);
        mStorePresenter.showList(mStoreRecyclerView, linearLayoutManager, spaceItemDecoration);
    }
    private final int resultCodeOth = 101;
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == resultCodeOth) {
            String selectCity = data.getStringExtra("selectCity");
            mStoreTitleBar.setRightText(selectCity);
        }
    }
}
